using System;
using System.Collections.Generic;
using Sce.PlayStation.Core.Graphics;

namespace Nyanimals
{
	public sealed class CShaderManager
	{
		private static readonly CShaderManager instance = new CShaderManager();
		private List<tShader> Shaders;
		
		private CShaderManager ()
		{
			Shaders = new List<tShader>();
		}
		public static CShaderManager Instance
		{
			get { return instance;}
		}
		
		public int AddShader(string szName)
		{
			// check for existing shader
			for(int shaderIndex = 0; shaderIndex < Shaders.Count; ++shaderIndex)
			{
				if(Shaders[shaderIndex].Name == szName)
				{
					return shaderIndex;
				}
			}
			
			// add the new shader
			int returnIndex = Shaders.Count;
			tShader shader = new tShader();
			shader.Name = new string(szName.ToCharArray());
			
			// string vcgName = "/Application/shaders/" + szName + ".vcg";
			// string fcgName = "/Application/shaders/" + szName + ".fcg";
			string cgxName = "/Application/shaders/" + szName + ".cgx";
			shader.Shader = new ShaderProgram(cgxName);
			Shaders.Add(shader);
			
			return returnIndex;
		}
		
		public void GetShader(int index, out tShader shader)
		{
			shader = Shaders[index];
		}
	}
}

